package com.samoyed.credit

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.samoyed.credit.Modle.ListDataModle

/**
 * @author longke
 * @date: 2021/10/30 17:52
 * @corporation: 深圳萨摩耶互联网金融服务公司
 * @description：
 */
object DataStr {
    fun getList(): ArrayList<ListDataModle> {
        val datalist = "[{\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"72\",\n" +
                "\t\"id\": 0,\n" +
                "\t\"ordercontent\": \"深圳市地铁相关运营主体\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"11月01日 星期一\",\n" +
                "\t\"type\": 1\n" +
                "}, {\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"16\",\n" +
                "\t\"id\": 1,\n" +
                "\t\"ordercontent\": \"丰e足食\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"11月01日 星期一\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 2,\n" +
                "\t\"amount\": \"18\",\n" +
                "\t\"id\": 2,\n" +
                "\t\"ordercontent\": \"路边早餐档包子\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"11月01日 星期一\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"16\",\n" +
                "\t\"id\": 3,\n" +
                "\t\"ordercontent\": \"美团平台商户\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"11月01日 星期一\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"22\",\n" +
                "\t\"id\": 4,\n" +
                "\t\"ordercontent\": \"美甲\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"11月01日 星期一\",\n" +
                "\t\"type\": 2\n" +
                "},{\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"72\",\n" +
                "\t\"id\": 0,\n" +
                "\t\"ordercontent\": \"深圳市地铁相关运营主体\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月30日 星期六\",\n" +
                "\t\"type\": 1\n" +
                "}, {\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"16\",\n" +
                "\t\"id\": 1,\n" +
                "\t\"ordercontent\": \"丰e足食\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月30日 星期六\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 2,\n" +
                "\t\"amount\": \"18\",\n" +
                "\t\"id\": 2,\n" +
                "\t\"ordercontent\": \"路边早餐档包子\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月30日 星期六\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"16\",\n" +
                "\t\"id\": 3,\n" +
                "\t\"ordercontent\": \"美团平台商户\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月30日 星期六\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"22\",\n" +
                "\t\"id\": 4,\n" +
                "\t\"ordercontent\": \"美甲\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月30日 星期六\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"60\",\n" +
                "\t\"id\": 5,\n" +
                "\t\"ordercontent\": \"美甲\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月29日 星期五\",\n" +
                "\t\"type\": 1\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"12\",\n" +
                "\t\"id\": 5,\n" +
                "\t\"ordercontent\": \"路边早餐档包子\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月29日 星期五\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"13\",\n" +
                "\t\"id\": 6,\n" +
                "\t\"ordercontent\": \"美团平台商户\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月29日 星期五\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"18\",\n" +
                "\t\"id\": 7,\n" +
                "\t\"ordercontent\": \"路边早餐档包子\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月29日 星期五\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 2,\n" +
                "\t\"amount\": \"17\",\n" +
                "\t\"id\": 8,\n" +
                "\t\"ordercontent\": \"湘粉人家\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月29日 星期五\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"186\",\n" +
                "\t\"id\": 9,\n" +
                "\t\"ordercontent\": \"美甲\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月28日 星期四\",\n" +
                "\t\"type\": 1\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"46\",\n" +
                "\t\"id\": 9,\n" +
                "\t\"ordercontent\": \"美甲\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月28日 星期四\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 1,\n" +
                "\t\"amount\": \"26\",\n" +
                "\t\"id\": 10,\n" +
                "\t\"ordercontent\": \"美团平台商户\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月28日 星期四\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"6\",\n" +
                "\t\"id\": 11,\n" +
                "\t\"ordercontent\": \"深圳市地铁相关运营主体\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月28日 星期四\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 2,\n" +
                "\t\"amount\": \"86\",\n" +
                "\t\"id\": 12,\n" +
                "\t\"ordercontent\": \"虎皮蛋糕香梨等11件\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月28日 星期四\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"6\",\n" +
                "\t\"id\": 13,\n" +
                "\t\"ordercontent\": \"深圳市地铁相关运营主体\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月28日 星期四\",\n" +
                "\t\"type\": 2\n" +
                "}, {\n" +
                "\t\"accountingtype\": 3,\n" +
                "\t\"amount\": \"16\",\n" +
                "\t\"id\": 14,\n" +
                "\t\"ordercontent\": \"湘粉人家\",\n" +
                "\t\"ordertype\": 2,\n" +
                "\t\"time\": \"10月28日 星期四\",\n" +
                "\t\"type\": 2\n" +
                "}]"
        val list = Gson().fromJson<ArrayList<ListDataModle>>(datalist, object : TypeToken<List<ListDataModle?>?>() {}.type)

        return list;
    }

    /**
     * 数组中是否有当天的数据
     */
    fun isHasDate(list: ArrayList<ListDataModle>, date: String): Int {
        var number = 0;
        list.forEach { s ->
            if (s.time == date) {
                number++
            }
        }
        return number
    }

    /**
     * 数组中是否有当天的数据
     */
    fun getIndex(list: ArrayList<ListDataModle>, date: String): Int {
        var position = 0;

        list.forEachIndexed { index, s ->
            if (s.time == date) {
                return index
            }
        }
        return position
    }

    /**
     * 获取某一月中的数据
     */
    fun getMonthList(list: ArrayList<ListDataModle>, month: String): MutableList<ListDataModle> {

        var newList = mutableListOf<ListDataModle>()
        list.filter { it.time.startsWith(month) }.forEach {
            newList.add(it)
        }
        return newList
    }

    /**
     * 获取某一月中的数据
     */
    fun getListSort(list: ArrayList<ListDataModle>): ArrayList<ListDataModle> {
        list.sortByDescending {
            it.time
        }
        return list
    }
}